package net.ak.dao.impl;

import java.util.List;

import net.ak.dao.UserMasterDao;
import net.ak.model.User;
import net.ak.model.UserMaster;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class UserMasterDaoImpl extends BaseDao<UserMaster> implements UserMasterDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<UserMaster> listUserMasterByUser(User user) {
		Session session 	= sessionFactory.getCurrentSession();
		Criteria criteria 	= session.createCriteria(UserMaster.class);
		criteria.add(Restrictions.eq("user_id", user.getId()));
		
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserMaster> listUserMasterByIP(String ip) {
		Session session 	= sessionFactory.getCurrentSession();
		Criteria criteria 	= session.createCriteria(UserMaster.class);
		criteria.add(Restrictions.eq("ip", ip));
		
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserMaster> listUserMasterByBrowser(String browser) {
		Session session 	= sessionFactory.getCurrentSession();
		Criteria criteria 	= session.createCriteria(UserMaster.class);
		criteria.add(Restrictions.eq("browser", browser));
		
		return criteria.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserMaster> listUserMaster() {
		Session session 	= sessionFactory.getCurrentSession();
		Criteria criteria 	= session.createCriteria(UserMaster.class);
		
		return criteria.list();
	}

}
